The TIA (as seen by the programmer)
3.0 Synchronization
3.1 Horizontal Timing
When the electron beam scans across the TV screen and
reaches the right edge, it must be turned off and moved
back to the left edge of the screen to begin the next scan
line. The TIA takes care of this automatically, independent
of the microprocessor. A 3.58 MHz oscillator generates
clock pulses called color clocks which go into a pulse
counter in the TIA. This counter allows 160 color clocks
for the beam to reach the right edge, then generates a
horizontal sync signal (HSYNC) to return the beam to the
left edge. It also generates the signal to turn the beam
off (horizontal blanking) during its return time of 68
color clocks. Total round trip for the electron beam is
160 + 68 = 228 color clocks. Again, all the horizontal
timing is taken care of by the TIA without assistance from
the microprocessor.
3.2 Microprocessor Synchronization
The microprocessors clock is the 3.58 MHz oscillator
divided by 3, so one machine cycle is 3 color clocks.
Therefore, one complete scan line of 228 color clocks
allows only 76 machine cycles (228/3 = 76) per scan line.
The microprocessor must be synchronized with the TIA on a
line-by-line basis, but program loops and branches take
unpredictable lengths of time. To solve this software
sync. problem, the programmer can use the WSYNC (Wait for
SYNC) strobe register. Simply writing to the WSYNC causes
the microprocessor to halt until the electron beam reaches
the right edge of the screen, then the microprocessor
resumes operation at the beginning of the 68 color clocks
for horizontal blanking. Since the TIA latches all
instructions until altered by another write operation, it
could be updated every 2 or 3 lines. The advantage is the
programmer gains more time to execute software, but at a
price paid with lower vertical resolution in the graphics.
NOTE: WSYNC and all the following addresses bit
structures are itemized in the TIA hardware manual. The
purpose of this document is to make them understandable.
3.3 Vertical timing
When the electron beam has scanned 262 lines, the TV set
must be signaled to blank the beam and position it at the
top of the screen to start a new frame. This signal is
called vertical sync, and the TIA must transmit this signal
for at least 3 scan lines. This is accomplished by writing
a 1 in D1 of VSYNC to turn it on, count at least 2 scan
lines, then write a 0 to D1 of VSYNC to turn it off.
To physically turn the beam off during its repositioning
time, the TV set needs 37 scan lines of vertical blanks
signal from the TIA. This is accomplished by writing a 1
in D1 of VBLANK to turn it on, count 37 lines, then write a
0 to D1 of VBLANK to turn it off. The microprocessor is
of course free to execute other software during the
vertical timing commands, VSYNC and VBLANK.